/*
** my_str_to_wordtab.c for  in /exam//rendu/ex_9
**
** Made by gregory gueux
** Login   <gueux_g@epitech.net>
**
** Started on  Sat Oct 27 12:19:41 2012 gregory gueux
** Last update Thu May 16 14:33:01 2013 adrien lamaison
*/

#include "../include/my.h"
#include <stdlib.h>

int	countword(char *str)
{
  int	m;
  int	i;

  i = 0;
  m = 1;
  while (str[i])
    {
      if (str[i] == ' ' || str[i] == '\n')
	m++;
      i++;
    }
  return (m);
}

char	**my_str_to_wordtab(char *str)
{
  char	**tab;
  int	a;
  int	i;
  int	tmp;
  int	count;
  char	*save;

  a = 0;
  i = 0;
  save = my_strdup(str);
  tab = (void *)xmalloc(sizeof(*tab) * countword(str) + 1);
  count = countword(str);
  while (str[i])
    {
      while (str[i] == ' ')
      	i++;
      if ((str[i] != ' ' && str[i] != '\n') && a < count)
      	{
	  tmp = i;
	  while (str[i] != ' ' && str[i] != '\n')
	    i++;
	  save[i] = '\0';
      	  tab[a] = save + tmp;
	  a++;
      	}
      i++;
    }
  return (tab);
}
